SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE VIEW dbo.vwPrestamosParaBanco
AS
SELECT l.Año, l.NumeroPeriodo, SUM(la.MontoMensual) AS MontoP, loc.localidad
FROM  dbo.tb_Alumnos a INNER JOIN
               dbo.tb_BecasYPrestamos byp ON a.idAlumno = byp.Alumno INNER JOIN
               dbo.tb_MovimientosBYP m ON m.IdBecaYPrestamo = byp.idBeca INNER JOIN
               dbo.tb_LiquidacionBYP l ON l.idLiquidacionByP = m.LiquidacionByP INNER JOIN
               dbo.tb_LineasDeBYP la ON la.idLineaDeBYP = l.IdLineaDeByP INNER JOIN
               dbo.tb_Localidades loc ON loc.idLocalidad = a.Localidad
WHERE (la.idTipoBecaOprestamo = 2)
--and a.Documento in (SELECT documento from documentosAprocesarBecas)
GROUP BY l.Año, l.NumeroPeriodo, loc.localidad


GO
GRANT SELECT ON  [dbo].[vwPrestamosParaBanco] TO [Becas]
GRANT SELECT ON  [dbo].[vwPrestamosParaBanco] TO [SoloVer]
GO
